﻿@functions
{
    string GenerateHtmlAttributes(ModelMetadata metadata)
    {
        var retVal = Html.GetUnobtrusiveValidationAttributes(metadata.PropertyName, metadata);
      
        var classes = new List<string>();
        if (metadata.AdditionalValues.ContainsKey("expandable"))
            classes.Add("expandable");

        if (classes.Any())
            retVal.Add("class", string.Join(" ", classes));

        if (metadata.AdditionalValues.ContainsKey("autofocus"))
            retVal.Add("autofocus", null);

        var result = string.Empty;

        foreach (var value in retVal)
        {
            result = result + value.Key + "=\"" + value.Value + "\" ";
        }
        return result;
    }
}

<input type="hidden" name="@ViewData.ModelMetadata.PropertyName" value="<%=@ViewData.ModelMetadata.PropertyName %>" id="@ViewData.ModelMetadata.PropertyName" @Html.Raw(GenerateHtmlAttributes(ViewData.ModelMetadata)) />